from django.db import models
from django.contrib.auth.models import User



#   用户资金表
class UserMoney(models.Model):
    user_id = models.ForeignKey(User, on_delete=models.CASCADE)
    balance = models.DecimalField(max_digits=18, decimal_places=2,default=0)
    class Meta:
        db_table = "UserMoney"


#   资金变更记录
class RangeRMB(models.Model):
    user_id = models.ForeignKey(User, on_delete=models.CASCADE)
    change_morey = models.DecimalField(max_digits=18, decimal_places=2)
    change_type	= models.IntegerField(default=0)
    change_time = models.DateTimeField(auto_now_add=False)
    order_no = models.CharField(max_length=100, default='')
    class Meta:
        db_table = "RangeRMB"


#   商品类型表
class CommodityCategory(models.Model):
    category_name = models.CharField(max_length=50)
    class Meta:
        db_table = "CommodityCategory"


#   商品表
class Commodity(models.Model):
    commodity_no = models.CharField(max_length=100)
    stock = models.IntegerField(default=0)
    category_id = models.ForeignKey(CommodityCategory, on_delete=models.CASCADE)
    commodity_name = models.CharField(max_length=100)
    cover = models.CharField(max_length=200)
    price = models.DecimalField(max_digits=18, decimal_places=2)
    class Meta:
        db_table = "Commodity"



#   订单表
class UserOrder(models.Model):
    order_no = models.CharField(max_length=100)
    user_id = models.ForeignKey(User, on_delete=models.CASCADE)
    commodity_no = models.CharField(max_length=100)
    buy_count = models.IntegerField(default=1)
    pay_money = models.DecimalField(max_digits=18, decimal_places=2)
    pay_time = models.DateTimeField(default='')
    is_good = models.IntegerField(default=1)
    is_pay = models.IntegerField(default=0)
    add_time = models.DateTimeField(auto_now_add=False)
    is_random = models.IntegerField(default=0)
    class Meta:
        db_table = "UserOrder"


